package user.zc;
import java.awt.*;
import javax.swing.*;

/**
 * @author zhouchuang
 * @date 2023/8/16 11:29
 */
public class GridBagLayoutExample {
    public static void main(String[] args) {
        JFrame frame = new JFrame("GridBagLayout Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new GridBagLayout());

        // 创建 GridBagConstraints 对象
        GridBagConstraints gbc = new GridBagConstraints();

        // 添加按钮到容器中
        JPanel line0 = new JPanel(new FlowLayout(FlowLayout.LEFT));
        line0.add( new JLabel("Button 1"));
        JTextField textField =  new JTextField("asdf");
        textField.setPreferredSize(new Dimension(400,50));
        line0.add(textField);
//        line0.setPreferredSize(new Dimension(500,50));
        gbc.gridx = 0; // 列索引
        gbc.gridy = 0; // 行索引
        gbc.weighty = 1.0; // 设置行的比例
        frame.add(line0, gbc);


        JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
        line1.add(new JLabel("Button 2"));
        line1.add(new JTextField("",50));
        gbc.gridx = 0; // 列索引
        gbc.gridy = 1; // 行索引
        gbc.weighty = 9.0; // 设置行的比例
        line1.setBackground(Color.GRAY);
        line1.setPreferredSize(new Dimension(500,500));
        frame.add(line1, gbc);


       /* JTextArea button2 = new JTextArea(10,40);
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.weighty = 9.0; // 设置行的比例
        frame.add(button2, gbc);*/

        frame.pack();
        frame.setVisible(true);
    }
}

